package com.lonty.intelligence.service;

import com.lonty.intelligence.mapper.DynamicMapper;
import com.lonty.intelligence.model.Dynamic;
import com.lonty.intelligence.util.UUIDUtil;
import com.lonty.intelligence.vo.DynamicVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author 陈璇
 * @Date 2020/6/9 14:22
 * @Version 1.0
 */
@Service
public class DynamicService {

    @Resource
    private DynamicMapper dynamicMapper;

    /**
     * 添加动态
     * @param dynamicVo
     * @return
     */
    public boolean saveDynamic(DynamicVo dynamicVo){
        Dynamic dynamic = new Dynamic();
        BeanUtils.copyProperties(dynamicVo, dynamic);
        dynamic.setId(UUIDUtil.randomID());
        dynamic.setCreateTime(LocalDateTime.now());
        dynamic.setIsDel(0);
        return dynamicMapper.saveDynamic(dynamic) > 0;
    }

    /**
     * 根据类型获取动态
     * @param type
     * @return
     */
    public List<Dynamic> getDynamic(Integer type){
        return dynamicMapper.getDynamic(type);
    }

    /**
     * 根据ID获取动态
     * @param id
     * @return
     */
    public Dynamic getById(String id){
        return dynamicMapper.getById(id);
    }

    /**
     * 删除动态
     * @param id
     * @return
     */
    public boolean deleteDynamic(String id){
        return dynamicMapper.deleteDynamic(id) > 0;
    }

}
